package com.wx.app.ui.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.administrator.newemptyapplication.R;
import com.wx.app.mylib.app.BaseFragment;
import com.wx.app.ui.activity.CalendarActivity;
import com.wx.app.ui.activity.FilterActivity2;
import com.wx.app.ui.activity.FlowLayoutActivity;
import com.wx.app.ui.activity.GreenDaoActivity;
import com.wx.app.ui.activity.KeyBoardActivity;
import com.wx.app.ui.activity.OkHttpActivity;
import com.wx.app.ui.activity.PermissionActivity;
import com.wx.app.ui.activity.PopUpActivity;
import com.wx.app.ui.activity.Test2;
import com.wx.app.ui.activity.Test3;
import com.wx.app.ui.activity.Test4;
import com.wx.app.ui.activity.TestActivity;
import com.wx.app.ui.view.MenuDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class HomeFragment extends BaseFragment {
    private static final int RC_CAMERA_PERM = 123;
    private View layout;
    @BindView(R.id.btn_greendao)
    Button btnGreenDao;
    @BindView(R.id.btn_ok)
    Button btnOk;
    @BindView(R.id.btn_test)
    Button btnTest;
    @BindView(R.id.btn_test2)
    Button btnTest2;
    @BindView(R.id.btn_test3)
    Button btnTest3;
    @BindView(R.id.btn_main_test4)
    Button btnTest4;
    @BindView(R.id.btn_pop)
    Button btnPop;
    @BindView(R.id.btn_permission)
    Button btnPermission;
    @BindView(R.id.btn_shopping)
    Button btnShopping;
    private Bitmap mBitmap;

    public HomeFragment() {
        // Required empty public constructor
    }

    @SuppressLint("ValidFragment")
    public HomeFragment(String s) {

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (layout == null) {
            layout = inflater.inflate(R.layout.fragment_home, container, false);
            ButterKnife.bind(this, layout);

        }
        return layout;
    }

    @OnClick(R.id.btn_filter2)
    void filter() {
        Intent intent = new Intent(mActivity, FilterActivity2.class);
        startActivity(intent);
        getActivity().overridePendingTransition(R.anim.base_slide_right_in, R.anim.base_slide_right_out);
    }

    @OnClick(R.id.btn_flow_layout)
    void flowLayout() {
        Intent intent = new Intent(mActivity, FlowLayoutActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.btn_permission)
    void clickPermission() {
        Intent intent = new Intent(mActivity, PermissionActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.btn_greendao)
    void clickGreenDao() {
        Intent intent = new Intent(getActivity(), GreenDaoActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.btn_ok)
    void clickOk() {
        Intent intent2 = new Intent(getActivity(), OkHttpActivity.class);
        startActivity(intent2);
    }

    @OnClick(R.id.btn_test)
    void test() {
        Intent intent3 = new Intent(getActivity(), TestActivity.class);
        startActivity(intent3);
    }

    @OnClick(R.id.btn_test2)
    void test2() {
        Intent intent4 = new Intent(getActivity(), Test2.class);
        startActivity(intent4);
    }

    @OnClick(R.id.btn_test3)
    void test3() {
        Intent intent5 = new Intent(getActivity(), Test3.class);
        startActivity(intent5);
    }

    @OnClick(R.id.btn_main_test4)
    void test4() {
        Intent intent = new Intent(getActivity(), Test4.class);
        startActivity(intent);
    }

    @OnClick(R.id.btn_pop)
    void popUp() {
        Intent intent = new Intent(mActivity, PopUpActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.btn_shopping)
    void shopping() {

        JSONArray array = new JSONArray();
        for (int i = 0; i < 10; i++) {
            JSONObject object = new JSONObject();
            object.put("text", "文本内容");
            array.add(object);
        }

        MenuDialog menuDialog = new MenuDialog(mActivity);

        Window dialogWindow = menuDialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.START | Gravity.TOP);

        lp.x = 0; // 新位置X坐标
        lp.y = 0; // 新位置Y坐标
        lp.width = 800; // 宽度
        lp.height = 600; // 高度
        lp.alpha = 0.7f; // 透明度


        // 当Window的Attributes改变时系统会调用此函数,可以直接调用以应用上面对窗口参数的更改,也可以用setAttributes
        // dialog.onWindowAttributesChanged(lp);
        dialogWindow.setAttributes(lp);
        menuDialog.show();

    }

    @OnClick(R.id.btn_keyboard)
    void keyboard() {
        Intent intent = new Intent(mActivity, KeyBoardActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.btn_canlander)
    void canlander() {
        Intent intent = new Intent(mActivity, CalendarActivity.class);
        startActivity(intent);
    }
}
